package io.github.xiaoxing365.listeners;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import io.github.xiaoxing365.Base64.Base64Explainer;
import io.github.xiaoxing365.jframeIni.MainFrameIni;

public class ButtonListener {

    public ButtonListener(){
        listener();
    }

    public void listener(){
        MainFrameIni frameIni = new MainFrameIni();
        frameIni.getButton().addActionListener(listener->{
            String text = frameIni.getTextField().getText();
            System.out.println("123");
        try {
            boolean isMD5Entrited = Pattern.matches("^(?:[A-Za-z-z0-9+/]{4})*(?:[A-Za-z-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",text);
            if (isMD5Entrited) {
                JLabel label = new JLabel("是Base64加密文本");
                String md5explained = Base64Explainer.convertBase64(text);
                frameIni.getTextField2().setText(md5explained);
                frameIni.getFrame().add(label);
                frameIni.getFrame().pack();
            }else{
                JLabel label = new JLabel("非Base64加密文本！");
                frameIni.getFrame().add(label);
                frameIni.getFrame().pack();
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        
        });
    }
}
